package com.example.myapplication.apter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.ActivityListBean;
import com.example.myapplication.management.EventDetailsActivity;

import java.util.List;

public class CtivityListApter extends  RecyclerView.Adapter<CtivityListApter.MyServer>{

    private Context context;
    private List<ActivityListBean.RowsBean> list;
    private View view;

    public CtivityListApter(Context context, List<ActivityListBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyServer onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_civitylist,null);
        return new MyServer(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyServer holder, int position) {
        Glide.with(context).load("http://124.93.196.45:10001"+list.get(position).getImgUrl()).into(holder.activity_image);
        holder.activity_name.setText(list.get(position).getName());
        holder.activity_signup_count.setText("报名人数:"+String.valueOf(list.get(position).getSignupNum()));
        holder.activity_likes_count.setText("点赞数:"+String.valueOf(list.get(position).getLikeNum()));
        //点击照片进入活动详情
        holder.li_civilist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, EventDetailsActivity.class);
                intent.putExtra("RowsBeanID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class MyServer extends RecyclerView.ViewHolder{

        private ImageView activity_image;
        private TextView activity_name;
        private TextView activity_signup_count;
        private TextView activity_likes_count;
        private LinearLayout li_civilist;

        public MyServer(@NonNull View itemView) {
            super(itemView);
            activity_image = itemView.findViewById(R.id.activity_image);
            li_civilist = itemView.findViewById(R.id.li_civilist);
            activity_name = itemView.findViewById(R.id.activity_name);
            activity_signup_count = itemView.findViewById(R.id.activity_signup_count);
            activity_likes_count = itemView.findViewById(R.id.activity_likes_count);
        }
    }
}
